package com.xuan.juc.lock8;

import java.util.concurrent.TimeUnit;

/*
*  1个静态的同步方法 1个普通同步方法 只有一个对象 先 发短信？打电话？
* */
public class LockTest3 {
    public static void main(String[] args) throws InterruptedException {
        Phone3 phone3 = new Phone3();
        Phone3 phone4 = new Phone3();

        new Thread(()->{
            phone3.sendMsg();
        },"A").start();

        TimeUnit.SECONDS.sleep(1);

        new Thread(()->{
            phone4.call();
        },"B").start();
    }
}


class Phone3{

    // synchronized 锁对象是方法的调用者！
    // static 因为类加载时候就有 所以锁的是class
    public static synchronized void sendMsg(){
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("sendMsg");
    }

    public static synchronized void call(){
        System.out.println("call");
    }

    public void hello(){
        System.out.println("hello");
    }
}
